#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/thread/thread.hpp>

#include <iostream>
#include <stdlib.h>
#include <string.h>


#include "Test.h"

using namespace std;
using boost::asio::ip::tcp;

#define max_len 1024
#define SERVER "192.168.1.123"
#define PORT 44444

class clientSession
	:public boost::enable_shared_from_this<clientSession>
{
public:
	clientSession(boost::asio::io_service& ioservice)
		:m_socket(ioservice)
	{
		memset(data_,'\0',sizeof(data_));
	}

	clientSession(boost::asio::io_service& ioservice,std::string ip)
		:m_socket(ioservice),m_ip(ip)
	{
		memset(data_,'\0',sizeof(data_));
	}
	~clientSession()
	{}
	tcp::socket& socket()
	{
		return m_socket;
	}
	
	void start();
public:
	void handle_write(const boost::system::error_code& error);
	void handle_read(const boost::system::error_code& error);
	void write(const std::string& data);
public:
	tcp::socket m_socket;
	char data_[max_len];
	std::string m_ip;
};

class serverApp
{
	typedef boost::shared_ptr<clientSession> session_ptr;
public:
	serverApp(boost::asio::io_service& ioservice,tcp::endpoint& endpoint);
	~serverApp()
	{
	}
private:
	void handle_accept(const boost::system::error_code& error,session_ptr& session);
private:
	boost::asio::io_service& m_ioservice;
	tcp::acceptor acceptor_;
};



